<?php
/**
 * Erstellt eine Linkreihe im Format RootLink > Link1 > Link2 > ...
 * 
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2010 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 * 
 * */


Class Yapary_Menu_Breadcrumb Extends Yapary_Attribute
{
    /** @var Daten fuer Breadcrumb im Format array[] = array('typ'        => 'text|link',
     * 														 'text'       => $text,
     * 														 'url'        => $url,
     * 														 'title'      => $title
     * 														 'attributes' => $arrAttributes)
     * */
    private $arrData = array();
    
    private $delimiter = NULL;
    
    
    function __construct ($_delimiter = '<span class="breadcrumbDelimiter"> &gt; </span>')
    {
        $this->delimiter = $_delimiter;
    }
        
    
    /**
     * Fuegt einen neuen Eintrag hinzu
     * @param string $text			: Anzuzeigender Text
     * @param array $arrAttributes	: Angeben wie {style|class|id|...}
     * @return true
     * */
    public function addText ($text, array $arrAttributes = array())
    {
        $this->arrData[] = array('typ'        => 'text',
                                 'text'       => $text,
                                 'attributes' => $arrAttributes);        
        return true;
    }

    
    /**
     * Fuegt einen neuen Eintrag hinzu
     * @param string $text			: Anzuzeigender Text
     * @param string|NULL $url		: Url fuer Links
     * @param string $title			: Title fuer Link
     * @param array $arrAttributes	: Angeben wie {style|class|id|rel|rev|...}
     * @return true
     * */
    public function addLink ($text, $url, $title, array $arrAttributes = array())
    {
        $this->arrData[] = array('typ'        => 'link',
                                 'text'       => $text,
                                 'url'        => $url,
                                 'title'      => $title,
                                 'attributes' => $arrAttributes);
        return true;
    }
    
    
    public function display ()
    {
        $result = '';
        $count = count($this->arrData);
        if ($count >= 1) {
            while (list($i, $arrVal) = each($this->arrData)) {
                $typ           = $arrVal['typ'];
                $text          = $arrVal['text'];
                $arrAttributes = $arrVal['attributes'];
                
                if ($typ == 'link') {
                    $url   = $arrVal['url'];
                    $title = $arrVal['title'];
                    
                    $arrAttributes['class'] = (isset($arrAttributes['class'])) ? 'breadcrumbLink '.$arrAttributes :  'breadcrumbLink';
                    $result .= '<a href="'.$url.'" title="'.$title.'"'.$this->arrayToAttribute($arrAttributes, true).'>'.$text.'</a>';
                } else {
                    $arrAttributes['class'] = (isset($arrAttributes['class'])) ? 'breadcrumbText '.$arrAttributes :  'breadcrumbText';
                    $result .= '<span'.$this->arrayToAttribute($arrAttributes, true).'>'.$text.'</span>';
                }
                
                if ($count > $i+1) {
                    $result .= $this->delimiter;
                }
            }
            reset($this->arrData);
        }
        
        return '<div class="breadcrumb">'.$result.'</div>';
    }
    
    
}


?>